﻿//Popup Login
$(document).ready(function () {
    //Chỉ nhập số (number) vào input
    $(".number").keypress(function (e) {
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });
    $('img').attr('onerror', 'this.src=\'/Images/System/no_image.gif\'');
    //
    $('.to_top').click(function () {
        $('body,html').animate({ scrollTop: 0 }, 800);
    });
    //
    $('#search_quick').click(function () {
        var strKeyWord = $('#txtKeyword').val();
        window.location.href = "/tim-kiem?q=" + strKeyWord;
    });
    //Login=================================================
    $('#btn-login-users').click(function () {
        xLoginUsers();
    });
    //
    var currentDate = new Date();
    $(".date").datepicker({ dateFormat: 'dd/mm/yy' });
    $(".date").datepicker("setDate", currentDate);
    //
});

/*=====================liblary function================================*/
jQuery.fn.errorItem = function (message) {
    $(this).addClass("error-item");
    $(this).attr("placeholder", message);
};
/*=====================================================================*/

//Goto Error
jQuery.fn.goToError = function () {
    $('html,body').animate({ scrollTop: ($("#notifition").offset().top - 10) }, 'slow');
};

//LOAD DANH SACH HANG SO
function xGetHangSo(tv_id, type) {
    $.ajax({
        type: "POST",
        url: "/Default.aspx/fncGetHangSo_ByID",
        data: '{TV_ID: "' + tv_id + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var Data = response.d;
            switch (type) {
                case 'huong-dan':
                    $(".huong-dan").html(Data);
                    break;
                case 'tai-sao':
                    $(".tai-sao").html(Data);
                    break;
                default:
                    $(".tai-sao").html("");
                    break;
            }
        },
        failure: function (response) {
            //alert("failure: " + response.d);
        },
        error: function (response) {
            //alert("error: " + response.d);
        }
    });
}

// Check định dạng Email
function xfomatEmail(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}
